<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <script th:src="@{/js/jquery-3.4.1.js}"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../../static/css/layui.css" th:href="@{/css/layui.css}"/>
    <script th:src="@{/js/layui.js}"></script>
    <script th:src="@{/js/modules/layer.js}"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #F5F6F9;
        }

        .header {
            background-color: #fff;
            text-align: center;
            padding: 20px 0;
            margin-bottom: 20px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .header h1 {
            color: #333;
            font-size: 28px;
        }

        .container {
            max-width: 90%;
            margin: auto;
        }

        .user-info {
            background-color: #fff;
            padding: 20px;
            margin-bottom: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .user-info span {
            font-weight: bold;
            color: #333;
            margin-right: 15px;
        }

        .btn-outline-info {
            border-color: #17a2b8;
            color: #17a2b8;
        }

        .table {
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .table th, .table td {
            padding: 15px;
        }

        .table thead th {
            background-color: #f8f9fa;
            color: #495057;
        }
    </style>
</head>
<body>
<div class="header">
    <h1>公寓水电管理系统</h1>
</div>
<div class="container">
    <div class="user-info">
        <span>用户： <span th:text="${username}"></span></span>
        <span>总费用： <span th:text="${cost}"></span></span>
        <span> 电价(元/度)： <span th:text="${perWater}"></span></span>
        <span> 水价(元/吨)： <span th:text="${perElec}"></span></span>
        <button class="btn btn-outline-info float-right" onclick="outLogon()">退出登录</button>
        <button class="btn btn-outline-info" onclick="message(this.value)" th:value="${username}">消息</button>

    </div>

    <table class="table table-striped table-bordered text-center">
        <thead>
        <tr>
            <th>月份</th>
            <th>用水量 (吨)</th>
            <th>用电量 (度)</th>
            <th>总费用 (元)</th>
            <th>创建时间</th>
            <th>更新时间</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="info : ${waterElectricityInfo}">
            <td th:text="${#dates.format(info.usageMonth, 'yyyy-MM')}"></td>
            <td th:text="${info.totalWaterUsage}"></td>
            <td th:text="${info.totalElectricityUsage}"></td>
            <td th:text="${info.cost}"></td>
            <td th:text="${#dates.format(info.createdAt, 'yyyy-MM-dd HH:mm')}"></td>
            <td th:text="${#dates.format(info.updatedAt, 'yyyy-MM-dd HH:mm')}"></td>
        </tr>
        </tbody>
    </table>

</div>
<script>
    function outLogon() {
        alert("退出登录成功")
        window.open("/logon", "_parent");
    }
    function message(username){
        let baseApi1 = "/root/";
        commonMethod123.layerOpen("消息", baseApi1 + 'show msg?username='+username);
    }

    var commonMethod123 = {
        layerOpen: function (title, url) {
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: title,
                    shade: 0.1,
                    area: ['700px', '600px'],
                    content: url
                });
            });
        }
    }
</script>
</body>
</html>
